#pragma once
#include"RBTree.h"

template<class K>
class my_set
{
	struct KeyOfT
	{
		const K& operator()(const K& data)
		{
			return data;
		} 
	};
public:
	typedef typename BRTree<K, const K, KeyOfT>::iterator iterator;
	typedef typename BRTree<K, const K, KeyOfT>::const_iterator const_iterator;
	iterator begin()
	{
		return _t.begin();
	}
	iterator end()
	{
		return _t.end();
	}
	const_iterator begin()const
	{
		return _t.begin();
	}
	const_iterator end()const
	{
		return _t.end();
	}
	std::pair<iterator, bool> insert(const K& key)
	{
		return _t.Insert(key);
	}
	iterator find(const K& key)
	{
		return _t.Find(key);
	}
private:
	BRTree<K, const K, KeyOfT> _t;
};
void PrintSet(const my_set<int>& s)
{
	for (auto e : s)
	{
		cout << e << endl;
	}
}

void test_set()
{
	my_set<int> s;
	s.insert(4);
	s.insert(2);
	s.insert(5);
	s.insert(15);
	s.insert(7);
	s.insert(1);
	s.insert(5);
	s.insert(7);

	PrintSet(s);
	my_set <int>s1(s);
	PrintSet(s1);
	my_set<int>s2 = s1;
	PrintSet(s2);
	cout << "\n";
	my_set<int>::iterator it = s.begin();
	while (it != s.end())
	{
		//*it += 5;

		cout << *it << " ";
		++it;
	}
	cout << endl;

	for (auto e : s)
	{
		cout << e << " ";
	}
	cout << endl;

	my_set<int> copy = s;
	for (auto e : copy)
	{
		cout << e << " ";
	}
	cout << endl;
	//cout << copy._t.IsBalance() << endl;
}
